package org.lzy.shop.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import org.lzy.shop.R
import org.lzy.shop.response.CouponResponse

class CouponAdapter: BaseQuickAdapter<CouponResponse.ListDTO, QuickViewHolder>()  {

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): QuickViewHolder {
        return QuickViewHolder(R.layout.item_coupon_list, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: CouponResponse.ListDTO?) {
        item?.let {
            holder.setText(R.id.coupon_title, item.title)
            holder.setText(R.id.endTime, "有效期至: "+ item.endTime)
            holder.setText(R.id.amount, "￥ "+ item.amount.toString())
            holder.setText(R.id.fullamount, "满 "+ item.condition?.fullAmount+"元可用")
            if (item.useStatus == 1) {
                holder.itemView.isEnabled=true
                holder.setTextColor(R.id.coupon_title,getResColor(R.color.OnSurface))
                holder.setTextColor(R.id.endTime,getResColor(R.color.OnSurface))
                holder.setTextColor(R.id.amount,getResColor(R.color.colorError))
                holder.setTextColor(R.id.fullamount,getResColor(R.color.OnSurface))
                holder.setVisible(R.id.get_now,false)
                holder.setVisible(R.id.user_coupon,true)
            }else{
                //优惠劵使用状态不可用点击无效，文字灰色
                holder.itemView.isEnabled=false
                holder.setTextColor(R.id.coupon_title,getResColor(R.color.OnSurface))
                holder.setTextColor(R.id.endTime,getResColor(R.color.OnSurface))
                holder.setTextColor(R.id.amount,getResColor(R.color.colorError))
                holder.setTextColor(R.id.fullamount,getResColor(R.color.OnSurface))
                holder.setVisible(R.id.get_now,true)
                holder.setVisible(R.id.user_coupon,false)
            }

        }


    }

    fun getResColor(resid: Int): Int {
        return ContextCompat.getColor(context, resid)
    }

}